package com.lgq.controller;

import com.lgq.bean.Message;
import com.lgq.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: stu_info_manager
 * @description:
 * @author: Lin
 * @create: 2019-01-03 16:35
 **/
@Controller
public class UserController {
    /**
     * 自动装配loginService
     */
    @Autowired
    private LoginService loginService;


    /**
     * 判断是否登录成功
     * 登录成功时把用户名放入session域中
     * @param loginName
     * @param password
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/login.do",method = RequestMethod.POST)
    public Message login(@RequestParam("loginName") String loginName, @RequestParam("password") String password, HttpServletRequest request){
        if(loginService.check(loginName,password)){
            request.getSession().setAttribute("loginName",loginName);
            return Message.success();
        }else{
            return Message.fail();
        }
    }
}
